package com.ruoyi.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.HospitalBed;
import com.ruoyi.hospital.service.IHospitalBedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 床位Controller
 * 
 * @author qichi
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/hospital/HospitalBed")
public class HospitalBedController extends BaseController
{
    @Autowired
    private IHospitalBedService hospitalBedService;

    /**
     * 查询床位列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:HospitalBed:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalBed hospitalBed)
    {
        startPage();
        List<HospitalBed> list = hospitalBedService.selectHospitalBedList(hospitalBed);
        return getDataTable(list);
    }

    /**
     * 导出床位列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:HospitalBed:export')")
    @Log(title = "床位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalBed hospitalBed)
    {
        List<HospitalBed> list = hospitalBedService.selectHospitalBedList(hospitalBed);
        ExcelUtil<HospitalBed> util = new ExcelUtil<HospitalBed>(HospitalBed.class);
        util.exportExcel(response, list, "床位数据");
    }

    /**
     * 获取床位详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:HospitalBed:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hospitalBedService.selectHospitalBedById(id));
    }

    /**
     * 新增床位
     */
    @PreAuthorize("@ss.hasPermi('hospital:HospitalBed:add')")
    @Log(title = "床位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalBed hospitalBed)
    {
        return toAjax(hospitalBedService.insertHospitalBed(hospitalBed));
    }

    /**
     * 修改床位
     */
    @PreAuthorize("@ss.hasPermi('hospital:HospitalBed:edit')")
    @Log(title = "床位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalBed hospitalBed)
    {
        return toAjax(hospitalBedService.updateHospitalBed(hospitalBed));
    }

    /**
     * 删除床位
     */
    @PreAuthorize("@ss.hasPermi('hospital:HospitalBed:remove')")
    @Log(title = "床位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hospitalBedService.deleteHospitalBedByIds(ids));
    }
}
